﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace YGWebMobileApi.Data
{
    /// <summary>
    /// 存放标记有 MobileAPIAttribute 特性的方法的相关信息
    /// </summary>
    public class MobileAPIDescription
    {
        public string Code { get; private set; }
        public string Name { get; private set; }
        public Type ClassType { get; private set; }

        /// <summary>
        /// 存放标记有 MobileAPIAttribute 特性的方法的相关信息
        /// </summary>
        /// <param name="type"></param>
        /// <param name="code"></param>
        /// <param name="name"></param>
        public MobileAPIDescription(Type type, string code, string name)
        {
            this.ClassType = type;
            this.Code = code;
            this.Name = name;
        }

        /// <summary>
        /// 创建实例
        /// </summary>
        /// <returns></returns>
        public IProcessMessage CreateInstance()
        {
            object obj = System.Activator.CreateInstance(this.ClassType);
            IProcessMessage p = obj as IProcessMessage;
            if (p == null)
            {
                throw new Exception("类 " + this.ClassType.FullName + " 必须实现接口 IProcessMessage");
            }
            return p;
        }
    }
}